// pages/water-world/water-world.js
var util = require("../../utils/util.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        indicatorDots: true,
        vertical: false,
        autoplay: true,
        interval: 5000,
        duration: 500
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getBannerList();
        this.getArticleList();
    },
    toArticleDetail: function(e) {
        const articleId = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/article-detail/article-detail?article_id=' + articleId
        })
    },
    getBannerList: function() {
        const _this = this;
        util.request(getApp().api.index.banner, { type: 2 }).then(
            function(res) {
                if (res.code == 200) {
                    _this.setData({
                        banner_list: res.data
                    });
                    if (res.data.length <= 1) {
                        _this.setData({
                            indicatorDots: false
                        })
                    }
                } else {
                    wx.showToast({
                        title: res.msg, //提示的内容,
                        icon: "none", //图标,
                        //duration: 1500, //延迟时间,
                        mask: false, //显示透明蒙层，防止触摸穿透,
                    });
                    setTimeout(function() {
                        wx.hideToast();
                    }, 1500);
                    return
                }
            }
        );
    },
    getArticleList: function() {
        const _this = this;
        util.request(getApp().api.article.list, { headName: '今日水知识' }).then(
            function(res) {
                if (res.code == 200) {
                    _this.setData({
                        article_list: res.data.list,
                        friends_list: res.data.friendsTopList,
                        new_list: res.data.newList,
                        science_list: res.data.scienceWaterList,
                        knowledge_list: res.data.knowledgeList,
                        top_list: res.data.listTop,
                    });
                } else {
                    wx.showToast({
                        title: res.msg, //提示的内容,
                        icon: "none", //图标,
                        //duration: 1500, //延迟时间,
                        mask: false, //显示透明蒙层，防止触摸穿透,
                    });
                    setTimeout(function() {
                        wx.hideToast();
                    }, 1500);
                    return
                }
            }
        );
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },
})